/**
 * Os metodos desta classe foram refatoradas para facilitar a leitura dos nomes das mesmas
 */
package PasswordCheckerSegundaIteracao;

public class PasswordCheckerBaseSegundaIteracao
{
	public int checkLength(String inputPassword)
	{
		int passwordScore = 0;
		
		if (inputPassword.length() < 5)
		{
			passwordScore += 3;
		}
		else if (inputPassword.length() > 5 && inputPassword.length() < 8)
		{
			passwordScore += 6;
		}
		else if (inputPassword.length() > 7 && inputPassword.length() < 16)
		{
			passwordScore += 12;
		}
		else if (inputPassword.length() > 16)
		{
			passwordScore += passwordScore + 18;
		}
		
		return passwordScore;
	}
	
	public int checkUppercaseLetters(String inputPassword)
	{
		int passwordScore = 0;
		
		for (char a : inputPassword.toCharArray())
		{
			if (Character.isLetter(a))
			{
				if (Character.isUpperCase(a))
				{
					passwordScore = (passwordScore + 5);
					break;
				}
			}
		}
		return passwordScore;
	}
	
	public int checkLowercaseLetters(String inputPassword)
	{
		int passwordScore = 0;
		
		for (char a : inputPassword.toCharArray())
		{
			if (Character.isLetter(a))
			{
				if (Character.isLowerCase(a))
				{
					passwordScore = (passwordScore + 1);
					break;
				}
			}
		}
		return passwordScore;
	}
	
	public void checkPassword(String inputPassword)
	{
		int passwordScore = 0;
		String passwordStreght = "weak";
		String message = "";

		

		

		

		for (char a : inputPassword.toCharArray())
		{
			if (Character.isDigit(a))
			{
				passwordScore = (passwordScore + 5);
				message = message + "5 points for at least one number\n";
				break;
			}
		}

		int cont = 0;
		for (int i = 0; i < inputPassword.length(); i++)
		{
			if (Character.isDigit(inputPassword.charAt(i)))
			{
				cont++;
			}
		}

		if (cont >= 3)
		{
			passwordScore = (passwordScore + 5);
			message = message + "5 points for at least three numbers\n";
		}

		char simbs[] = new char[11];
		simbs[0] = '!';
		simbs[1] = '@';
		simbs[2] = '#';
		simbs[3] = '$';
		simbs[4] = '%';
		simbs[5] = '^';
		simbs[6] = '&';
		simbs[7] = '*';
		simbs[8] = '?';
		simbs[9] = '_';
		simbs[10] = '~';

		int contSimbs = 0;

		for (int i = 0; i < inputPassword.length(); i++)
		{
			for (int j = 0; j < simbs.length; j++)
			{
				if (inputPassword.charAt(i) == simbs[j])
				{
					contSimbs++;
				}
			}
		}

		if (contSimbs >= 1)
		{
			passwordScore = (passwordScore + 5);
			message = message + "5 points for at least one special char\n";
		}

		if (contSimbs >= 2)
		{
			passwordScore = (passwordScore + 5);
			message = message + "5 points for at least two special chars\n";
		}

		boolean lower = false;
		boolean upper = false;

		for (int i = 0; i < inputPassword.length(); i++)
		{
			if (Character.isLowerCase(inputPassword.charAt(i)))
			{
				lower = true;
			}

			if (Character.isUpperCase(inputPassword.charAt(i)))
			{
				upper = true;
			}
		}

		if (lower && upper)
		{
			passwordScore = (passwordScore + 2);
			message = message + "2 combo points for upper and lower letters\n";
		}

		boolean number = false;
		for (int i = 0; i < inputPassword.length(); i++)
		{
			if (Character.isDigit(inputPassword.charAt(i)))
			{
				number = true;
			}
		}

		if ((lower || upper) && number)
		{
			passwordScore = (passwordScore + 2);
			message = message + "2 combo points for letters and numbers\n";
		}

		if ((cont > 0 || lower || upper) && contSimbs > 0)
		{
			passwordScore = (passwordScore + 2);
			message = message
					+ "2 combo points for (letters or numbers) and special chars\n";
		}

		if (passwordScore < 16)
		{
			passwordStreght = "very weak";
		}
		else if (passwordScore > 15 && passwordScore < 25)
		{
			passwordStreght = "weak";
		}
		else if (passwordScore > 24 && passwordScore < 35)
		{
			passwordStreght = "medium";
		}
		else if (passwordScore > 34 && passwordScore < 45)
		{
			passwordStreght = "strong";
		}
		else
		{
			passwordStreght = "stronger";
		}

		System.out.println("Strength score is: " + passwordScore);
		System.out.println("Strength verdict: " + passwordStreght);
		System.out.println("Log: " + message);
	}
}
